package com.seminario.rest.client;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.seminario.model.Registro;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

public class RegistroCliente {
	
	public List<Registro> ListAll(String url) {

		Type listType = new TypeToken<ArrayList<Registro>>() {
		}.getType();
		Gson gson = new Gson();

		Client client = Client.create();
		WebResource webResource = client.resource(url);
		ClientResponse response = webResource.accept("application/json").get(
				ClientResponse.class);
		String output = response.getEntity(String.class);

		return gson.fromJson(output, listType);
	}
	
	public Registro ListId(String url, int id) {

		Gson gson = new Gson();

		Client client = Client.create();
		WebResource webResource = client.resource(url + "/" +  id);
		ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
		String output = response.getEntity(String.class);

		return gson.fromJson(output, Registro.class);
	}
}
